package com.thinkfit.jy.activity;

import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.common.lib.bean.BrandInfoBean;
import com.common.lib.constant.EventBusEvent;
import com.common.lib.manager.DataManager;
import com.common.lib.network.HttpListener;
import com.common.lib.network.HttpMethods;
import com.common.lib.network.HttpObserver;
import com.thinkfit.jy.R;
import com.thinkfit.jy.utils.ThemeUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;

/**
 * 品牌信息及联系方式
 */
public class BrandInfoActivity extends MainActivity {

    BrandInfoBean brandInfo;
    RelativeLayout rlMain;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_brand_info;
    }

    public void init() {
        setViewsOnClickListener(R.id.ll_sport_back);
        rlMain = findViewById(R.id.rootView);
        if (DataManager.Companion.getInstance().getMainStyle() == 3) {
            setBackground(R.id.rootView, R.drawable.app_bg_xm);
            setBackground(R.id.llInfo, R.drawable.shape_33ffffff_20);
        }
//        getBrandInfo();
        resetDate();
    }

    public void initView(BrandInfoBean brandInfoBean){
        brandInfo = brandInfoBean;
        setViewsOnClickListener(R.id.ll_sport_back);
        System.out.println("ddddddddddddddddddddddd  brandInfoBean : "+brandInfoBean.toString());
//        setText(R.id.tv_company_name,brandInfo.getCompany());
//        setText(R.id.tv_company_web,"网址:"+brandInfo.getWeburl());
//        setText(R.id.tv_company_web,"电话:"+brandInfo.getTel());
    }

    @Override
    public void onResume() {
        super.onResume();
        rlMain.setBackgroundResource(ThemeUtils.getInstance().getMainTheme());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_sport_back:
                finish();
                break;
        }
    }


    protected void showBottomUI() {
    }

    @Override
    public boolean isMainActivity() {
        return false;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceive(HashMap<String, Object> map) {
        if (map == null) {
            return;
        }
        if (map.containsKey(EventBusEvent.TIME_CHANGE)) {
            resetDate();
        } else {
            super.onReceive(map);
        }
    }

    public void getBrandInfo(){
        HttpMethods.Companion.getInstance().brandInfo(new HttpObserver(this,new HttpListener<BrandInfoBean>() {
                    @Override
                    public void onSuccess(@Nullable BrandInfoBean bean) {
                        System.out.println("ddddddddddddddddddddddd  BrandInfoBean : "+bean.toString());
                        initView(bean);
                    }

                    @Override
                    public void dataError(int code, @Nullable String msg) {

                    }

                    @Override
                    public void connectError(@Nullable Throwable e) {

                    }
                },getCompositeDisposable()));
    }
}